

$(document).ready(function(){

	LoadSortbyClass();

	$("#sort_view_count").click(
		function(){
			SetSortBy( "1" )
		}
	);
	
	$("#sort_create_time").click(
		function(){
			SetSortBy( "2" )
		}
	);
	
	$("#sort_response_count").click(
		function(){
			SetSortBy( "3" )
		}
	);
	
	$("#sort_flower_count").click(
		function(){
			SetSortBy( "4" )
		}
	);
	
	$("#sort_contribution").click(
		function(){
			SetSortBy( "5" )
		}
	);
		
});

function SetSortBy( type ){
	//reset the sort by selector
	
	$( "#s" ).val(type);
	$( "#sortform" ).submit();
}

function LoadSortbyClass(){

	var sortby = $( "#s" ).val();
  
	if( sortby == '1' ){
	
		$( "#sort_view_count" ).replaceWith('<span>'+$( "#sort_view_count" ).text()+'</span>');
	}

	if( sortby == '2'  ){
	
		$( "#sort_create_time" ).replaceWith('<span>'+$( "#sort_create_time" ).text()+'</span>');
	}

	if( sortby == '3'  ){
	
		$( "#sort_response_count" ).replaceWith('<span>'+$( "#sort_response_count" ).text()+'</span>');
	}
	
	if( sortby == '4'  ){
	
		$( "#sort_flower_count" ).replaceWith('<span>'+$( "#sort_flower_count" ).text()+'</span>');
	}
	
	if( sortby == '5'  ){
	
		$( "#sort_contribution" ).replaceWith('<span>'+$( "#sort_contribution" ).text()+'</span>');
	}
	
}
